package server.workwithorder;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import abstractservlet.AbstractServlet;
import autoservice.api.controller.IAutoservice;
import controllers.Autoservice;


@WebServlet("/OrderList")
public class OrderList extends AbstractServlet {
	private static final String ORDERS = "orders";
	private static final String DATE = "date";
	private static final String BEGIN = "begin";
	private static final String END = "end";
	private static final String ALL = "all";
	private static final String MADING = "mading";
	private static final String DELETED = "deleted";
	private static final String CANCELED = "canceled";
	private static final String ORDER_LIST_PAGE = "/workwithorderpages/OrderListPage.jsp";
	private static final String DELIMITER = " ";
	private static final String GET_ORDER_LIST_OPERAT = "get order list";
	private ArrayList<String> answer = null;
	private static final long serialVersionUID = 1L;
	private IAutoservice autoservice = Autoservice.getInstance();
       
   
    public OrderList() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String orders = request.getParameter(ORDERS);
		String type = request.getParameter(DATE);
		String begin = request.getParameter(BEGIN);
		String end = request.getParameter(END);
		String parameters = null;		
		
		if(orders.equals(ALL)){
			answer = autoservice.SortAllOrder(type);
		}else if(orders.equals(MADING)){			
			answer = autoservice.SortMadingOrder(type);
		}else if(orders.equals(DELETED)){
			parameters = type+DELIMITER+begin+DELIMITER+end;
			answer = autoservice.SortDeletedOrderByPeriod(parameters);
		}else if(orders.equals(CANCELED)){
			parameters = type+DELIMITER+begin+DELIMITER+end;
			answer = autoservice.SortCanceledOrderByPeriod(parameters);
		}else{
			parameters = type+DELIMITER+begin+DELIMITER+end;
			answer = autoservice.SortMadeOrderByPeriod(parameters);
		}				
		super.navigate(request, response, GET_ORDER_LIST_OPERAT, answer, ORDER_LIST_PAGE);
		
		
	}
	
	
}
